#!/usr/bin/env node
//网课
//引用模块
// const Radio = require('./03-radio');

// //定义一个电台对象
// let station = {
//   freq: '106.7',
//   name: 'music station'
// };

// //实例化
// let radio = new Radio(station);
// //打开事件响应
// radio.on('open', function (station) {
//   console.log('"%s" FM %s opened', station.name, station.freq);
//   console.log('lalalala');
// });

// radio.on('open', function (station) {
//   console.log('hello', station);
//   console.log('\neventNames:', radio.eventNames());
//   console.log('\nopen listener count:', radio.listenerCount('open'));
//   console.log('\nopen listeners:', radio.listeners('open'));
// });

// //停止
// radio.on('stop', function (station) {
//   console.log('"%s" FM %s closed', station.name, station.freq);
// })

import { Radio } from './03-radio.js';

// 定义一个 station 对象
const station = {
  freq: '98.7',
  name: 'Rock FM'
};

// 实例化 Radio 对象
const radio = new Radio(station);

// 处理 Radio 对象的 play 事件
radio.on('play', (station) => {
  console.log(`Radio is playing on station ${station.name} at frequency ${station.freq}.`);
});

// 处理 Radio 对象的 stop 事件
radio.on('stop', (station) => {
  console.log(`Radio has stopped playing on station ${station.name}.`);
});

// 触发 play 和 stop 事件
radio.play();
radio.stop();
